﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using testapi.Data;
using Microsoft.Extensions.DependencyInjection;

namespace testapi.Services
{
    public class ServiceContext
    {
        private DbContext _dbContext;

        private readonly IServiceProvider _serviceProvider;


        public ServiceContext(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }
   
        public DbContext DbContext
        {
            get
            {
                if (_dbContext == null)
                    _dbContext = _serviceProvider.GetService<DataContext>();
                return _dbContext;
            }
           
        }
    }
}
